package com.lagou;/**
 * Created by IntelliJ IDEA.
 * User: Yangdx.
 * Date: 2020/12/14.
 * Time: 2:14.
 * Tags: Code, we are serious.
 */

import com.lagou.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author
 * @create 2020-12-14 2:14
 **/
@Component
@Slf4j
public class OrderDlxListener {
    @Resource
    private OrderMapper orderMapper;
    /**
     * 监听死信队列
     */
    @RabbitListener(queues = "dlx.queue")
    public void orderConsumer(String orderId) {
        //查询数据库该订单状态
        log.info("查询数据库该订单状态,订单号为：{}",orderId);
        OrderVO orderVO = orderMapper.getOrderById(orderId);
        String status = orderVO.getStatus();
        if ("待支付".equals(status)) {
            //更新数据库状态为超时未支付
            orderVO.setStatus("超时未支付");
            orderMapper.updateOrderById(orderVO);
        }
    }
}
